<template>
  <div class="fdsBusinessStartRuleset-remove-component">
    <el-dialog
      v-if="modelValue.visible"
      v-model="modelValue.visible"
      title="提示"
      width="400px"
    >
      <span
        >当前操作将{{
          modelValue.form.enabled ? '启用' : '禁用'
        }}该清洗规则,是否继续？</span
      >
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="danger" @click="ensure"> 确定 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
//提示弹框。
import { ElMessage } from 'element-plus'
import { updateFdsCleaningRuleset } from '@/api/fds-cleaning-ruleset.api'
//获取从父组件传来的数据。
const props = defineProps(['modelValue'])

const ensure = () => {
  let id = props.modelValue.form.id
  let formData = {
    id,
    enabled: props.modelValue.form.enabled,
  }
  updateFdsCleaningRuleset(formData)
    .then((res) => {
      cancel()
      ElMessage({
        message: '操作成功',
        type: 'success',
      })

      if (props.modelValue.refreshDataList) {
        props.modelValue.refreshDataList()
      }
    })
    .catch((err) => {
      cancel()
      ElMessage({
        message: err.msg || err,
        type: 'error',
      })
    })
}

const cancel = () => {
  props.modelValue.visible = false
}
</script>
<style lang="scss" scoped></style>
